/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package tracker.android.sens.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import tracker.android.sens.SensPackage;
import tracker.android.sens.Sensor;
import tracker.android.sens.SensorEvent;
import tracker.android.sens.SensorManager;
import tracker.android.sens.SensorThread;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Sensor Thread</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link tracker.android.sens.impl.SensorThreadImpl#getSensorManager <em>Sensor Manager</em>}</li>
 *   <li>{@link tracker.android.sens.impl.SensorThreadImpl#getLastUpdate <em>Last Update</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SensorThreadImpl extends ThreadImpl implements SensorThread {
	/**
	 * The cached value of the '{@link #getSensorManager() <em>Sensor Manager</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSensorManager()
	 * @generated
	 * @ordered
	 */
	protected SensorManager sensorManager;

	/**
	 * The default value of the '{@link #getLastUpdate() <em>Last Update</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLastUpdate()
	 * @generated
	 * @ordered
	 */
	protected static final long LAST_UPDATE_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getLastUpdate() <em>Last Update</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLastUpdate()
	 * @generated
	 * @ordered
	 */
	protected long lastUpdate = LAST_UPDATE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SensorThreadImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SensPackage.Literals.SENSOR_THREAD;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SensorManager getSensorManager() {
		return sensorManager;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSensorManager(SensorManager newSensorManager, NotificationChain msgs) {
		SensorManager oldSensorManager = sensorManager;
		sensorManager = newSensorManager;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SensPackage.SENSOR_THREAD__SENSOR_MANAGER, oldSensorManager, newSensorManager);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSensorManager(SensorManager newSensorManager) {
		if (newSensorManager != sensorManager) {
			NotificationChain msgs = null;
			if (sensorManager != null)
				msgs = ((InternalEObject)sensorManager).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SensPackage.SENSOR_THREAD__SENSOR_MANAGER, null, msgs);
			if (newSensorManager != null)
				msgs = ((InternalEObject)newSensorManager).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SensPackage.SENSOR_THREAD__SENSOR_MANAGER, null, msgs);
			msgs = basicSetSensorManager(newSensorManager, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SensPackage.SENSOR_THREAD__SENSOR_MANAGER, newSensorManager, newSensorManager));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getLastUpdate() {
		return lastUpdate;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLastUpdate(long newLastUpdate) {
		long oldLastUpdate = lastUpdate;
		lastUpdate = newLastUpdate;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SensPackage.SENSOR_THREAD__LAST_UPDATE, oldLastUpdate, lastUpdate));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void onSensorChanged(SensorEvent event) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Byte> float2Byte(EList<Float> inData) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SensPackage.SENSOR_THREAD__SENSOR_MANAGER:
				return basicSetSensorManager(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SensPackage.SENSOR_THREAD__SENSOR_MANAGER:
				return getSensorManager();
			case SensPackage.SENSOR_THREAD__LAST_UPDATE:
				return getLastUpdate();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SensPackage.SENSOR_THREAD__SENSOR_MANAGER:
				setSensorManager((SensorManager)newValue);
				return;
			case SensPackage.SENSOR_THREAD__LAST_UPDATE:
				setLastUpdate((Long)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SensPackage.SENSOR_THREAD__SENSOR_MANAGER:
				setSensorManager((SensorManager)null);
				return;
			case SensPackage.SENSOR_THREAD__LAST_UPDATE:
				setLastUpdate(LAST_UPDATE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SensPackage.SENSOR_THREAD__SENSOR_MANAGER:
				return sensorManager != null;
			case SensPackage.SENSOR_THREAD__LAST_UPDATE:
				return lastUpdate != LAST_UPDATE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (lastUpdate: ");
		result.append(lastUpdate);
		result.append(')');
		return result.toString();
	}

} //SensorThreadImpl
